import 'package:flutter/material.dart';

class SettingsScreen extends StatelessWidget {
  const SettingsScreen({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: const Color(0xFFF8F9FA),
      appBar: AppBar(
        title: const Text('设置'),
        backgroundColor: Colors.white,
        foregroundColor: const Color(0xFF333333),
        elevation: 0,
        leading: IconButton(
          icon: const Icon(Icons.arrow_back_ios, size: 16),
          onPressed: () {
            Navigator.pop(context);
          },
        ),
      ),
      body: SingleChildScrollView(
        child: Column(
          children: [
            const SizedBox(height: 16),
            
            // 账户设置
            _buildSettingsSection(
              context,
              '账户设置',
              [
                _buildSettingsItem(
                  context,
                  '修改密码',
                  Icons.lock_outline,
                  const Color(0xFFE6F7FF),
                  const Color(0xFF1890FF),
                  onTap: () {
                    // TODO: 跳转到修改密码页面
                    ScaffoldMessenger.of(context).showSnackBar(
                      const SnackBar(content: Text('修改密码功能开发中')),
                    );
                  },
                ),
                _buildSettingsItem(
                  context,
                  '绑定手机',
                  Icons.phone_outlined,
                  const Color(0xFFFFF7E6),
                  const Color(0xFFFAAD14),
                  subtitle: '138****8888',
                  onTap: () {
                    // TODO: 跳转到绑定手机页面
                    ScaffoldMessenger.of(context).showSnackBar(
                      const SnackBar(content: Text('绑定手机功能开发中')),
                    );
                  },
                ),
                _buildSettingsItem(
                  context,
                  '绑定邮箱',
                  Icons.email_outlined,
                  const Color(0xFFF0FFF4),
                  const Color(0xFF52C41A),
                  subtitle: 'user@example.com',
                  onTap: () {
                    // TODO: 跳转到绑定邮箱页面
                    ScaffoldMessenger.of(context).showSnackBar(
                      const SnackBar(content: Text('绑定邮箱功能开发中')),
                    );
                  },
                ),
              ],
            ),
            
            const SizedBox(height: 20),
            
            // 通知设置
            _buildSettingsSection(
              context,
              '通知设置',
              [
                _buildSwitchItem(
                  context,
                  '推送通知',
                  Icons.notifications_outlined,
                  const Color(0xFFE6F7FF),
                  const Color(0xFF1890FF),
                  true,
                  (value) {
                    // TODO: 处理推送通知开关
                  },
                ),
                _buildSwitchItem(
                  context,
                  '交易提醒',
                  Icons.swap_vert,
                  const Color(0xFFF0FFF4),
                  const Color(0xFF52C41A),
                  true,
                  (value) {
                    // TODO: 处理交易提醒开关
                  },
                ),
                _buildSwitchItem(
                  context,
                  '系统消息',
                  Icons.message_outlined,
                  const Color(0xFFFFF1F0),
                  const Color(0xFFF5222D),
                  false,
                  (value) {
                    // TODO: 处理系统消息开关
                  },
                ),
              ],
            ),
            
            const SizedBox(height: 20),
            
            // 隐私设置
            _buildSettingsSection(
              context,
              '隐私设置',
              [
                _buildSettingsItem(
                  context,
                  '隐私政策',
                  Icons.privacy_tip_outlined,
                  const Color(0xFFE6F7FF),
                  const Color(0xFF1890FF),
                  onTap: () {
                    // TODO: 跳转到隐私政策页面
                    ScaffoldMessenger.of(context).showSnackBar(
                      const SnackBar(content: Text('隐私政策页面开发中')),
                    );
                  },
                ),
                _buildSettingsItem(
                  context,
                  '用户协议',
                  Icons.description_outlined,
                  const Color(0xFFFFF7E6),
                  const Color(0xFFFAAD14),
                  onTap: () {
                    // TODO: 跳转到用户协议页面
                    ScaffoldMessenger.of(context).showSnackBar(
                      const SnackBar(content: Text('用户协议页面开发中')),
                    );
                  },
                ),
                _buildSwitchItem(
                  context,
                  '数据分析',
                  Icons.analytics_outlined,
                  const Color(0xFFF0FFF4),
                  const Color(0xFF52C41A),
                  true,
                  (value) {
                    // TODO: 处理数据分析开关
                  },
                ),
              ],
            ),
            
            const SizedBox(height: 20),
            
            // 其他设置
            _buildSettingsSection(
              context,
              '其他',
              [
                _buildSettingsItem(
                  context,
                  '关于我们',
                  Icons.info_outline,
                  const Color(0xFFE6F7FF),
                  const Color(0xFF1890FF),
                  onTap: () {
                    // TODO: 跳转到关于我们页面
                    ScaffoldMessenger.of(context).showSnackBar(
                      const SnackBar(content: Text('关于我们页面开发中')),
                    );
                  },
                ),
                _buildSettingsItem(
                  context,
                  '版本更新',
                  Icons.system_update_outlined,
                  const Color(0xFFFFF7E6),
                  const Color(0xFFFAAD14),
                  subtitle: 'v1.0.0',
                  onTap: () {
                    // TODO: 检查版本更新
                    ScaffoldMessenger.of(context).showSnackBar(
                      const SnackBar(content: Text('当前已是最新版本')),
                    );
                  },
                ),
                _buildSettingsItem(
                  context,
                  '清除缓存',
                  Icons.cleaning_services_outlined,
                  const Color(0xFFF0FFF4),
                  const Color(0xFF52C41A),
                  subtitle: '128MB',
                  onTap: () {
                    // TODO: 清除缓存功能
                    ScaffoldMessenger.of(context).showSnackBar(
                      const SnackBar(content: Text('缓存清除成功')),
                    );
                  },
                ),
              ],
            ),
            
            const SizedBox(height: 40),
          ],
        ),
      ),
    );
  }
  
  Widget _buildSettingsSection(BuildContext context, String title, List<Widget> items) {
    return Container(
      margin: const EdgeInsets.symmetric(horizontal: 20),
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(16),
        boxShadow: const [
          BoxShadow(
            color: Color(0x1A000000),
            blurRadius: 20,
            offset: Offset(0, 4),
          ),
        ],
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Padding(
            padding: const EdgeInsets.fromLTRB(20, 20, 20, 10),
            child: Text(
              title,
              style: const TextStyle(
                fontSize: 18,
                fontWeight: FontWeight.bold,
                color: Color(0xFF333333),
              ),
            ),
          ),
          ...items,
          const SizedBox(height: 10),
        ],
      ),
    );
  }
  
  Widget _buildSettingsItem(
    BuildContext context,
    String title,
    IconData icon,
    Color iconBgColor,
    Color iconColor,
    {String? subtitle,
    VoidCallback? onTap}
  ) {
    return GestureDetector(
      onTap: onTap,
      child: Container(
        margin: const EdgeInsets.symmetric(horizontal: 20, vertical: 5),
        padding: const EdgeInsets.symmetric(vertical: 12),
        decoration: BoxDecoration(
          color: const Color(0xFFF8F9FA),
          borderRadius: BorderRadius.circular(8),
        ),
        child: Row(
          children: [
            const SizedBox(width: 16),
            // 图标
            Container(
              width: 32,
              height: 32,
              decoration: BoxDecoration(
                color: iconBgColor,
                borderRadius: BorderRadius.circular(16),
              ),
              child: Center(
                child: Icon(icon, color: iconColor, size: 18),
              ),
            ),
            const SizedBox(width: 16),
            // 标题和副标题
            Expanded(
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Text(
                    title,
                    style: const TextStyle(
                      fontSize: 16,
                      color: Color(0xFF333333),
                    ),
                  ),
                  if (subtitle != null) ...[
                    const SizedBox(height: 2),
                    Text(
                      subtitle,
                      style: const TextStyle(
                        fontSize: 12,
                        color: Color(0xFF999999),
                      ),
                    ),
                  ],
                ],
              ),
            ),
            // 箭头
            const Icon(
              Icons.arrow_forward_ios,
              size: 14,
              color: Color(0xFF999999),
            ),
            const SizedBox(width: 16),
          ],
        ),
      ),
    );
  }
  
  Widget _buildSwitchItem(
    BuildContext context,
    String title,
    IconData icon,
    Color iconBgColor,
    Color iconColor,
    bool value,
    ValueChanged<bool> onChanged,
  ) {
    return Container(
      margin: const EdgeInsets.symmetric(horizontal: 20, vertical: 5),
      padding: const EdgeInsets.symmetric(vertical: 12),
      decoration: BoxDecoration(
        color: const Color(0xFFF8F9FA),
        borderRadius: BorderRadius.circular(8),
      ),
      child: Row(
        children: [
          const SizedBox(width: 16),
          // 图标
          Container(
            width: 32,
            height: 32,
            decoration: BoxDecoration(
              color: iconBgColor,
              borderRadius: BorderRadius.circular(16),
            ),
            child: Center(
              child: Icon(icon, color: iconColor, size: 18),
            ),
          ),
          const SizedBox(width: 16),
          // 标题
          Expanded(
            child: Text(
              title,
              style: const TextStyle(
                fontSize: 16,
                color: Color(0xFF333333),
              ),
            ),
          ),
          // 开关
          Switch(
            value: value,
            onChanged: onChanged,
            activeColor: const Color(0xFF1890FF),
            activeTrackColor: const Color(0xFFE6F7FF),
            inactiveThumbColor: const Color(0xFF999999),
            inactiveTrackColor: const Color(0xFFF0F2F5),
          ),
          const SizedBox(width: 16),
        ],
      ),
    );
  }
}